<SCRIPT type="text/javascript" src="/view/javascripts/form.js"></SCRIPT>
<SCRIPT type="text/javascript">
function expandit(id){
    obj = document.getElementById(id);
    if (obj.style.display=="none") obj.style.display="";
    else obj.style.display="none";
  }
</SCRIPT>

<DIV class="block">
	<H1>



	<?php echo $response->getParameter('title');?></H1>
</DIV>
<DIV id="year">

<?php
$year = (int)unserialize($_SESSION['year']);
?>
	<FORM action="index.html" method="post">
		<INPUT type="hidden" name="year" value="<?php echo $year-1;?>"> <INPUT
			type="submit" value="&lt;&lt;&lt;">
	</FORM>

<?php
	echo $year;
	if ($year < date("Y")) {
?>
	<FORM action="index.html" method="post">
		<INPUT type="hidden" name="year" value="<?php echo $year+1;?>">
		<INPUT type="submit"  value="&gt;&gt;&gt;">
	</FORM>
<?php
	}
?>
</DIV>
<DIV class="block">
	<TABLE>
		<TR>
			<TH rowspan="3">Процесс</TH>
			<TH rowspan="3">Владелец</TH>
			<TH rowspan="3">Цель</TH>
			<TH rowspan="3">Показатель</TH>
			<TH rowspan="3">Весомость</TH>
			<TH rowspan="3">Плановое значение</TH>
			<TH colspan="8">Квартал календарного года</TH>
		</TR>
		<TR>
			<TH colspan="2">I</TH>
			<TH colspan="2">II</TH>
			<TH colspan="2">III</TH>
			<TH colspan="2">IV</TH>
		</TR>
		<TR>
			<TH>план</TH>
			<TH>факт</TH>
			<TH>план</TH>
			<TH>факт</TH>
			<TH>план</TH>
			<TH>факт</TH>
			<TH>план</TH>
			<TH>факт</TH>
		</TR>
			
	<?php
		$responsibilities = $response->getParameter('responsibilities');
		$indicatorValues = $response->getParameter('indicatorValues');
		foreach ($responsibilities as $type=>$typeResps) {
	?>
		<TR style="color:blue"><TD colspan="14"><STRONG><?php echo $type;?></STRONG></TD></TR>
	<?php
		foreach ($typeResps as $dep=>$resps) {
		?>
			<TR onclick="expandit('department<?php echo $dep; ?>');"><TD colspan="14"><STRONG><?php echo $dep;?></STRONG></TD></TR>
			<TBODY id="department<?php echo $dep; ?>" style="display: none">
			<?php
			$j=0;
			$count=array();//количество повторений данного процесса
			$count[]=1;
			for ($i = 1; $i <sizeof($resps); $i++) {
			if ($resps[$i]->getIndicator()->getProcess()->getIdentity() ==$resps[$i-1]->getIndicator()->getProcess()->getIdentity()) {
				$count[$j]++;
			} else {
				$j++;
				$count[]=1;
			}
			}
			$j=0;
			$k=1;
			for ($i = 0; $i <sizeof($resps); $i++) {
				//если строка первая или единственная в блоке, то выводим полностью
				if($k==1){
					?>
					<TR >
						<TD <?php if ($count[$j]>1) {
							echo "rowspan=\"$count[$j]\"";
						}?>><?php echo $resps[$i]->getIndicator()->getProcess()->getName();?></TD>
						<TD <?php if ($count[$j]>1) {
							echo "rowspan=\"$count[$j]\"";
						}?>><?php echo $resps[$i]->getIndicator()->getProcess()->getOwner()->getName();?></TD>
						<TD <?php if ($count[$j]>1) {
							echo "rowspan=\"$count[$j]\"";
						}?>><?php echo $resps[$i]->getIndicator()->getProcess()->getObject();?></TD>
						<TD><?php echo $resps[$i]->getIndicator()->getName();?></TD>
						<TD><?php echo $resps[$i]->getIndicator()->getWeight();?></TD>
						<TD><?php if ($resps[$i]->getIndicator()->getPlanValue()!=null){
								echo $resps[$i]->getIndicator()->getPlanValue();}
								else echo $resps[$i]->getPlanValue();?>
								</TD>
						<?php for ($q = 1; $q <= 4 ; $q++) {
							$str="white";
							if (isset($indicatorValues[$resps[$i]->getIdentity()][$q])) {
								if ($indicatorValues[$resps[$i]->getIdentity()][$q]->getPlanValue()>
								$indicatorValues[$resps[$i]->getIdentity()][$q]->getValue()) {
									$str="magenta";
								}
							}
							//плановое значение
							echo "<TD bgcolor=".$str.">";
							 
								if(isset($indicatorValues[$resps[$i]->getIdentity()][$q])){
			 						echo $indicatorValues[$resps[$i]->getIdentity()][$q]->getPlanValue();
			 					} else {
			 						echo "-";
			 					}
							echo"</TD>";
							//фактическое значение
							echo "<TD bgcolor=".$str.">";
							 
								if(isset($indicatorValues[$resps[$i]->getIdentity()][$q])) {
									echo $indicatorValues[$resps[$i]->getIdentity()][$q]->getValue();
								} else {
									echo "-";
								}
							
							echo "</TD>";
						} ?>
						
					</TR>
					<?php
					}else {
						?><TR>
							<TD><?php echo $resps[$i]->getIndicator()->getName();?></TD>
							<TD><?php echo $resps[$i]->getIndicator()->getWeight();?></TD>
							<TD><?php if ($resps[$i]->getIndicator()->getPlanValue()!=null){
								echo $resps[$i]->getIndicator()->getPlanValue();}
								else echo $resps[$i]->getPlanValue();?></TD>
								
						<?php for ($q = 1; $q <= 4 ; $q++) {
							$str="white";
							if (isset($indicatorValues[$resps[$i]->getIdentity()][$q])) {
								
								if ($indicatorValues[$resps[$i]->getIdentity()][$q]->getPlanValue()>
								$indicatorValues[$resps[$i]->getIdentity()][$q]->getValue()) {
									$str="magenta";
								}
							}
							
							echo "<TD bgcolor=".$str.">";
							
								if(isset($indicatorValues[$resps[$i]->getIdentity()][$q])){
									echo $indicatorValues[$resps[$i]->getIdentity()][$q]->getPlanValue();
								}else echo "-";
							
							echo"</TD>";
							echo "<TD bgcolor=".$str.">";
							
								if(isset($indicatorValues[$resps[$i]->getIdentity()][$q])) {
									echo $indicatorValues[$resps[$i]->getIdentity()][$q]->getValue();
								} else {
									echo "-";
								}
							
						echo "</TD>";
						} ?>
							</TR>
						<?php 
					}
					if($count[$j]==$k){
						$j++;
						$k=1;
					}else {
						$k++;
					}
			}
			
			?> </TBODY>
				<?php
	}	//foreach department
	?> </TBODY>
	<?php 
}//foreach departmentType


?>	</TABLE>

</DIV>

